package com.finger.gulimall.order.controller;

import com.finger.common.utils.R;
import com.finger.gulimall.order.entity.OrderEntity;
import com.finger.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @ClassName RabbitTestController
 * @Description TODO
 * @Author finger
 * @Date 2022/7/3 12:40
 * @Version 1.0
 */

@RestController
public class RabbitTestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/send")
    public String sendMsg(@RequestParam("num") Integer num) {
        for (int i = 0; i < num; i++) {
            if (i % 2 == 0) {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hello.exchange", "hello.queue", orderEntity);

            } else {
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();

                rabbitTemplate.convertAndSend("hello.exchange", "hello.queue", entity);
            }
        }
        return "ok";
    }

    @GetMapping("/sixin")
    public R sixin(){
        String str = "Hello";

        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",str);

        return R.ok();
    }

}
